home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-07-23 | 2.3 KB | 82 lines | [TEXT/KAHL] |
- /***************************************
- * benchmark.cp
- * benchmark template function and main routine
- ***************************************/
-
- #include "fix.h"
- #include "matrix.h"
- #include <math.h>
- #include <iostream.h>
- #include <console.h>
- #include <profile.h>
-
- // Change the 0 below to a 1 to use the profiler.
- // Also turn on the following C++ compiler options:
- // "Generate profiler calls"
- // "Always generate stack frames"
- // "Use function call for inlines"
- const int use_profiler = 0;
-
- const double pi = 3.14159;
- const int num_iterations = 1000;
-
- template <class Number>
- unsigned long benchmark(matrix<Number> m,const int use_prof=0)
- {
- unsigned long time1, time2, total;
-
- // Make the matrix an identity matrix, and print.
- m(0,0) = m(1,1) = m(2,2) = m(3,3) = 1;
- cout << "identity matrix:" << endl << m;
-
- // Create a rotation matrix, and print.
- matrix<Number> rotation;
- rotation(0,0) = rotation(1,1) = cos(pi/90); // 2 degree rotation
- rotation(0,1) = rotation(1,0) = sin(pi/90);
- rotation(0,1) *= -1;
- rotation(2,2) = rotation(3,3) = 1;
- cout << "rotation matrix:" << endl << rotation;
-
- // Premultiply the matrix by the rotation matrix 1000 times.
- GetDateTime(&time1);
- if (use_prof) InitProfile(200,200);
- for (int i=0; i<num_iterations; i++)
- m = rotation * m;
- if (use_prof) DumpProfile();
- GetDateTime(&time2);
-
- // Print results.
- cout << "result of " << num_iterations << " multiplications:" << endl << m;
- total = time2-time1;
- cout << "duration: " << total << " seconds" << endl;
- return total;
- }
-
- void main(int argc, char *argv[])
- {
- unsigned long double_time, fix_time;
- double ratio;
-
- // The ccommand() function allows results to be easily saved to a file.
- argc = ccommand(&argv);
-
- cout << "calling the benchmark function on a double matrix..." << endl;
- matrix<double> double_matrix;
- double_time = benchmark(double_matrix);
-
- cout << "calling the benchmark function on a fix matrix..." << endl;
- matrix<fix> fix_matrix;
- fix_time = benchmark(fix_matrix,use_profiler);
-
- if (!use_profiler)
- if (fix_time > 0)
- {
- ratio = (double)double_time/(double)fix_time;
- cout << "fixed-point calculations were about " << ratio
- << " times faster!" << endl;
- }
- else
- cout << "fixed-point calculations completed in less than 1 second!" << endl;
- }
-
-